<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>审核该用户界面</title>
    <link href="../../style/css/back/style.css" rel="stylesheet" type="text/css"/>
    <script src="../../style/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../style/js/ajaxfileupload.js"></script>
    <script src="../../style/js/ckeditor/ckeditor.js"></script>
    <script src="../../style/js/ckfinder/ckfinder.js"></script>
    <script type="text/javascript">
        var editor;
        $(function () {
            //使用ckeditor替换textArea
            editor  = CKEDITOR.replace("contentEditor");
            CKFinder.setupCKEditor(editor,'../../style/js/ckfinder')

            var newsId = location.search.split("=")[1];


            $.get("../../news/getNewsTypeList", function (res) {
                if (res.code === 500) {
                    alert(res.msg)
                } else if (res.code === 202) {
                    alert("登录失效")
                } else {
                    var str = "";
                    for (let i = 0; i < res.data.length; i++) {
                        str += "<option value='" + res.data[i].id + "'>" + res.data[i].name + "</option>"
                    }
                    $("#newsTypeId").append(str);
                }
            })

            $.get("../../news/getNewsById",{newsId:newsId}, function (res) {
                if (res.code === 202) {
                    alert("登录失效，请重新登录")
                    window.parent.location.replace("../../login.html");
                } else if (res.code === 500) {
                    alert(res.msg);
                } else {
                    $("#title").val(res.data.title);
                    $("#summary").val(res.data.summary);
                    var img = "http://127.0.0.1:8080/tomorrowNewsFiles/news/" + res.data.coverPicture
                    $("#imgId").html("<img width='200px' height='100px' src='"+img+"'/>" )
                    $("#txtArea").html(res.data.content)
                    $("option[value='"+res.data.newsId+"']").attr("select",true);
                }
            }, "json")
        })

        //保存修改（审核操作）
        function set() {
            $.post("../../", $("#addForm").serialize(), function (res) {
                if (res.code === 500) {
                    alert(res.msg);
                }else if(res.code === 200){
                    alert(res.msg)
                    location.replace("regList.html")
                }else {
                    alert("登录失效,请重新登录")
                    window.parent.location.replace("../../login.html");
                }
            })
        }
    </script>
</head>

<body>
<div class="formbody">
    <div class="formtitle"><span>添加信息</span></div>
    <form id="addForm">
        <input type="hidden" name="id" id="id"/>
        <input type="hidden" id="imgUrl" name="imgUrl">
        <ul class="forminfo">
            <li>
                <label>新闻标题</label>
                <input name="title" id="title" type="text" class="dfinput"/>
            </li>
            <li>
                <label>新闻类型</label>
                <select id="newsTypeId" name="newsId" class="dfinput">

                </select>
            </li>
            <li>
                <label>新闻摘要</label>
                <input name="summary" id="summary" type="text" class="dfinput"/>
            </li>
            <li>
                <label>封面图</label>
                <div id="imgId"></div>
                <input name="coverPicture" id="coverPicture" type="file" class="dfinput" accept=".jpg,.png"/>
            </li>
            <li>
                <label>正文</label>
                <textarea id="contentEditor">

                </textarea>
            </li>
            <li>
                <input type="button" class="btn" value="确认保存" onclick="save()"/>
                <input type="button" class="btn" value="保存并发布" onclick="saveAndSubmit()"/>
            </li>
        </ul>
    </form>

</div>
</body>
</html>
